package com.dsx.gyj.mysqlMain;

import java.sql.*;

/**
 * author:xiaoxue1272
 * date:2020/5/17-01:48
 */
public class ConnectionUtil {

    public static final String JDBC_URL = "jdbc:mysql://localhost:3306/1707c";
    public static final String JDBC_USER = "root";
    public static final String JDBC_PASSWORD = "127201";
    public static Connection connection = null;

    static {
        try {
            Class.forName("com.mysql.jdbc.Driver");
            connection = DriverManager.getConnection(JDBC_URL, JDBC_USER, JDBC_PASSWORD);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {

        }
    }

    public static ResultSet getSelectMethod(String sql){
        ResultSet rs = null;
        try {
            PreparedStatement ps = connection.prepareStatement(sql);
            rs = ps.executeQuery();
        } catch (SQLException e) {
            e.printStackTrace();
        }finally {
            return rs;
        }
    }

    public static int getOtherMethod(String sql){
        int result = 0;
        try {
            PreparedStatement ps = connection.prepareStatement(sql);
            result = ps.executeUpdate();
        } catch (SQLException e) {
            e.printStackTrace();
        }finally {
            return result;
        }
    }
}